/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.procurement.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.javaeye.common.dto.DTO;

public class SupplierOrder implements DTO {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6894920169941893269L;
	
	public static final int ORDER_TYPE_RECEIVE_SUPPLIER = 0;
	
	public static final int ORDER_TYPE_BACK_SUPPLIER = 1;
	
	public static final int ORDER_STATES_CREATED = 0;
	
	public static final int ORDER_STATES_ALL_RECEIVE = 1;
	
	public static final int ORDER_STATES_CUSTOM_FINISH = 2;
	
	private String id;//cyyyyMMddXX
	
	private Date createDate;
	
	private Date exceptArriveDate;
	
	private Date arriveDate;
	
	private String supplierName;
	
	private int supplierId;
	
	private String contractNo;
	
	private double totleAmount;
	
	private int status;
	
	private Date updateDate;
	
	private int orderType;
	
	private long materialsReceiveOrderCount;
	
	/**
	 * 删除的采购单明细ID
	 */
	private String removeDetailIds;

	private Set<SupplierOrderDetail> orderDetails = new HashSet<SupplierOrderDetail>();
	
	public void addDetail(SupplierOrderDetail detail) {
		detail.setOrder(this);
		orderDetails.add(detail);
	}
	
	public List<Integer> getRemoveDetailIdList() {
		List<Integer> ret = new ArrayList<Integer>();
		if (removeDetailIds != null && !"".equals(removeDetailIds.trim()) ) {
			String[] deleteIds = removeDetailIds.split(",");
			for (String deleteId : deleteIds) {
				if (!"".equals(deleteId)) {
					ret.add(new Integer(deleteId));
				}
			}
		}
		return ret;
	}
	
	public SupplierOrderDetail findDetailByDetailId(int detailId) {
		for (SupplierOrderDetail detail : orderDetails) {
			if (detail.getId() == detailId) {
				return detail;
			}
		}
		return null;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getExceptArriveDate() {
		return exceptArriveDate;
	}

	public void setExceptArriveDate(Date exceptArriveDate) {
		this.exceptArriveDate = exceptArriveDate;
	}

	public Date getArriveDate() {
		return arriveDate;
	}

	public void setArriveDate(Date arriveDate) {
		this.arriveDate = arriveDate;
	}

	public String getSupplierName() {
		return supplierName;
	}

	public void setSupplierName(String supplierName) {
		this.supplierName = supplierName;
	}

	public int getSupplierId() {
		return supplierId;
	}

	public void setSupplierId(int supplierId) {
		this.supplierId = supplierId;
	}

	public String getContractNo() {
		return contractNo;
	}

	public void setContractNo(String contractNo) {
		this.contractNo = contractNo;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public Set<SupplierOrderDetail> getOrderDetails() {
		return orderDetails;
	}

	public void setOrderDetails(Set<SupplierOrderDetail> orderDetails) {
		this.orderDetails = orderDetails;
	}

	public void setTotleAmount(double totleAmount) {
		this.totleAmount = totleAmount;
	}

	public double getTotleAmount() {
		return totleAmount;
	}
	
	public void setRemoveDetailIds(String removeDetailIds) {
		this.removeDetailIds = removeDetailIds;
	}

	public String getRemoveDetailIds() {
		return removeDetailIds;
	}
	
	public String getStatusName() {
		switch(status) {
		case ORDER_STATES_CREATED :
			if (orderType == ORDER_TYPE_BACK_SUPPLIER)
				return "等待出库";
			else
				return "未全部收货";
		case ORDER_STATES_ALL_RECEIVE :
			if (orderType == ORDER_TYPE_BACK_SUPPLIER)
				return "出库完成";
			else
			return "已全部收货";
		case ORDER_STATES_CUSTOM_FINISH :
			return "人工结束收货";
		default :
			return "";
		}
	}

	public void setOrderType(int orderType) {
		this.orderType = orderType;
	}

	public int getOrderType() {
		return orderType;
	}

	public long getMaterialsReceiveOrderCount() {
		return materialsReceiveOrderCount;
	}

	public void setMaterialsReceiveOrderCount(long materialsReceiveOrderCount) {
		this.materialsReceiveOrderCount = materialsReceiveOrderCount;
	}
	
}
